package com.github.captcha.generator.model.dto;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @Author: haichuan.lu
 * @date 2023/02/23 17:14
 * @Description 验证码实体
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ImageCaptcha {

    /** 背景图. */
    private String bgImage;

    /** 滑动图. */
    private String sliderImage;

    /** 背景图片所属标签. */
    private String bgImageTag;

    /** 模板图片所属标签. */
    private String sliderImageTag;

    /** 背景图片宽度. */
    private Integer bgImageWidth;

    /** 背景图片高度. */
    private Integer bgImageHeight;

    /** 滑块图片宽度. */
    private Integer sliderImageWidth;

    /** 滑块图片高度. */
    private Integer sliderImageHeight;

    /** 随机值. */
    private Integer randomX;

    /** 容错值, 可以为空 默认 0.02容错,校验的时候用. */
    private Float tolerant;

    /** 验证码类型. */
    private String type;

    /** 透传字段，用于传给前端. */
    private Object data;

    /**
     * 扩展字段
     */
    public Object expand;

    public ImageCaptcha(String bgImage, String sliderImage, String bgImageTag, String sliderImageTag,
                        Integer bgImageWidth, Integer bgImageHeight, Integer sliderImageWidth,
                        Integer sliderImageHeight, Integer randomX, String type) {
        this.bgImage = bgImage;
        this.sliderImage = sliderImage;
        this.bgImageTag = bgImageTag;
        this.sliderImageTag = sliderImageTag;
        this.bgImageWidth = bgImageWidth;
        this.bgImageHeight = bgImageHeight;
        this.sliderImageWidth = sliderImageWidth;
        this.sliderImageHeight = sliderImageHeight;
        this.randomX = randomX;
        this.type = type;
    }

    public static ImageCaptcha of(String bgImage, String sliderImage, String bgImageTag,
                                  String sliderImageTag, Integer bgImageWidth, Integer bgImageHeight,
                                  Integer sliderImageWidth, Integer sliderImageHeight, Integer randomX,
                                  String type) {
        return new ImageCaptcha(bgImage,
                sliderImage,
                bgImageTag,
                sliderImageTag,
                bgImageWidth,
                bgImageHeight,
                sliderImageWidth,
                sliderImageHeight,
                randomX, type);
    }
}
